/* Copyright(c) 2010- Siro-info Co.(http://www.siro-info.com)
 * All rights reserved.
 */
package com.siro.pm.model;

import com.siro.pm.I18nManager;
import com.siro.pm.utils.PmUtils;
import com.siro.pm.utils.UUIDGenerator;
import com.vaadin.addon.calendar.event.BasicEvent;

/**
 * Class Declaration:
 * 
 * @version v1.0
 * @since Attendance.java v1.0
 */
public class Attendance extends BasicEvent {
	private static final long serialVersionUID = 8858025113827160792L;

	public static String ATTENDANCE_STATUS_WORK = I18nManager
			.getMessage("attendance.work");
	public static String ATTENDANCE_STATUS_REST = I18nManager
			.getMessage("attendance.rest");
	public static String ATTENDANCE_STATUS_TRAVEL = I18nManager
			.getMessage("attendance.travel");
	public static String ATTENDANCE_STATUS_PERSONALLEAVE = I18nManager
			.getMessage("attendance.personalLeave");
	public static String ATTENDANCE_STATUS_SICKLEAVE = I18nManager
			.getMessage("attendance.sickLeave");

	public static String CURRENT_ATTENDANCE_STATUS = ATTENDANCE_STATUS_WORK;

	private String id;
	private String status;
	private String where;
	private String bankName;

	public Attendance() {
		setAllDay(true);
		if (id == null) {
			setId(UUIDGenerator.newUUID());
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
		if (status.equals(Attendance.ATTENDANCE_STATUS_WORK)) {
			setCaption(I18nManager.getMessage("attendance.work"));
			setDescription(I18nManager.getMessage("attendance.work"));
			setStyleName("attendance-work");
		}
		if (status.equals(Attendance.ATTENDANCE_STATUS_REST)) {
			setCaption(I18nManager.getMessage("attendance.rest"));
			setDescription(I18nManager.getMessage("attendance.rest"));
			setStyleName("attendance-rest");
		}
		if (status.equals(Attendance.ATTENDANCE_STATUS_TRAVEL)) {
			setCaption(I18nManager.getMessage("attendance.travel"));
			setDescription(I18nManager.getMessage("attendance.travel"));
			setStyleName("attendance-travel");
		}
		if (status.equals(Attendance.ATTENDANCE_STATUS_PERSONALLEAVE)) {
			setCaption(I18nManager.getMessage("attendance.personalLeave"));
			setDescription(I18nManager.getMessage("attendance.personalLeave"));
			setStyleName("attendance-leave");
		}
		if (status.equals(Attendance.ATTENDANCE_STATUS_SICKLEAVE)) {
			setCaption(I18nManager.getMessage("attendance.sickLeave"));
			setDescription(I18nManager.getMessage("attendance.sickLeave"));
			setStyleName("attendance-leave");
		}
	}

	public String getWhere() {
		return where;
	}

	public void setWhere(String where) {
		this.where = where;
	}

	public String getBankName() {
		return bankName;
	}

	public void setBankName(String bankName) {
		this.bankName = bankName;
	}

	public boolean equals(Object anObject) {
		if (anObject instanceof Attendance) {
			return this.getId().equals(((Attendance) anObject).getId());
		} else {
			return false;
		}
	}

	public int hashCode() {
		return getId().hashCode();
	}

	public UserAttendance toUserAttendance(String username) {
		UserAttendance userAttendance = new UserAttendance();
		userAttendance.setId(id);
		userAttendance.setStatus(status);
		userAttendance.setAttencedate(PmUtils.getSDF().format(getStart()));
		userAttendance.setUsername(username);
		userAttendance.setDescription(getDescription());
		userAttendance.setCitiname(where);
		userAttendance.setBankname(bankName);
		return userAttendance;
	}

}
